const express = require('express');
const qs = require('querystring');

const app = express();

// 解析表单数据的中间件
app.use((req, res, next) => {
  let str = '';

  req.on('data', (chunk) => {
    str += chunk;
  })

  req.on('end', () => { 
    const body = qs.parse(str);
    req.body = body;
    console.log('str:', body);
    next();
  })

})

app.get('/', (req, res) => {
  console.log('调用了', req);
  res.send(req.body);
});

app.listen(80, () => {
  console.log('Server listening on port 80');
});